/**
 * 
 */
package org.company.management.utilities;

import org.company.management.entity.EmployeeSchedule;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;

/**
 * @author Paner
 *
 */
public class EmployeeEditingSupport extends EditingSupport {

	private final TableViewer viewer;

	public EmployeeEditingSupport(TableViewer viewer) {
		super(viewer);
		this.viewer = viewer;
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return new TextCellEditor(viewer.getTable());
	}

	@Override
	protected boolean canEdit(Object element) {
		return false;
	}

	@Override
	protected Object getValue(Object element) {
		EmployeeSchedule employeeShedule = (EmployeeSchedule) element;
		String employeeName = "";
		if(employeeShedule.getEmployeeid() != null && employeeShedule.getEmployeeid().getLastname() != null)
		{
			employeeName = employeeShedule.getEmployeeid().getLastname();
		}
		
		return employeeName;
		
	}

	@Override
	protected void setValue(Object element, Object value) {
		if(value != null)
		{
			EmployeeSchedule employeeShedule = (EmployeeSchedule) element;
			if(employeeShedule.getEmployeeid() != null)
			{
				employeeShedule.getEmployeeid().setLastname(String.valueOf(value));
			}
		}
		viewer.refresh();
	}
	
}